-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(logger): log event functionality #1004
Conversation
📊 Package size report 1%↑
🤖 This report was automatically generated by pkg-size-action |
📊 Package size report 1%↑
🤖 This report was automatically generated by pkg-size-action |
📊 Package size report 1%↑
🤖 This report was automatically generated by pkg-size-action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
You can build and start a local docs website by running these two commands: | ||
You can build and start a local docs website by running: | ||
|
||
`npm run docs-website-build-run` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be cool in the future (not this PR) to have an additional combo command to run the docs & the API docs at the same time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's done here! I did not document it yet, my bad
https://github.com/awslabs/aws-lambda-powertools-typescript/pull/1004/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R35
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant something like (name is just an example):
"docs-run-docs-and-api": "npm run docs-runLocalDocker && npm run docs-api-build-run"
This command would allow you to run the documentation + the API docs so you can browse between both. Right now when editing locally, if you start from the docs and click on "API Docs" on the left navigation menu it gives you a 404 because there's nothing on the /api
path.
But again, we can do it at some point in the future!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR, looking forward to merge it!
A couple of minor notes, which I will capture in a separate issue for later:
- I'd like to see a corresponding method for manual mode like
logger.logEvent(event);
- this is purely syntactic sugar as you can easily dologger.debug('event', { event });
but still. - Since in the docs we call out that this method is for debugging only, I'd expect the log level to be
DEBUG
instead ofINFO
. - In the
packages/logger/src/middy.ts
docstring of theinjectLambdaContext
middleware we should document the new flag/new behaviour so that it appears also in the API docs. - In the new sub-section of the docs where we show this method, it'd be nice to have a log excerpt. I was not sure which key the event would use in the JSON log (
event
duh).
* feat(logger): log event, add business logic and unit tests * test(logger): add log event support * feat(logger): add env variable for log event * test(logger): middy * chore(logger): middy polish for log event * test(logger): fix log event unit tests * test(logger): unit + e2e tests for log event functionality * docs(logger): add log event * docs: add single line command for docs generation * docs: fix typo in env vars section
Description of your changes
This PR introduces a new functionality: logging Lambda events. Developers can opt in for this behaviour by one of the following methods:
logEvent
set totrue
to theinjectLambdaContext
middlewarelogEvent
set totrue
to theinjectLambdaContext
decoratorPOWERTOOLS_LOGGER_LOG_EVENT
to through while using the injectLambdaContext middleware/decoratorNote that this functionality is only available when using a middleware or decorator.
The Lambda invocation will then print one log item with the following key-value pairs:
logLevel
INFOmessage
key with valueLambda invocation event
event
key with the current Lambda invocation event as valueLogging a Lambda event is very typical use of a logger in AWS Lambda. This logic aims to simplify and reduce the code that developers need to maintain.
How to verify this change
See E2E tests results.
To see the docs:
Related issues, RFCs
#482
PR status
Is this ready for review?: YES
Is it a breaking change?: NO
Checklist
Breaking change checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.